/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-22
 * Time: 16:52
 */
//有三个线程，分别只能打印A，B和C
//要求按顺序打印ABC，打印10次
public class Test {
    public static void main(String[] args) {
        Object lock1=new Object();
        Object lock2=new Object();
        Object lock3=new Object();
        Thread t1=new Thread(){
            @Override
            public void run() {
                try{
                    sleep(1000);
                    for(int i=0;i<10;i++){
                        System.out.print("A");
                        synchronized(lock1){
                            lock1.notify();
                        }
                        synchronized (lock3){
                            lock3.wait();
                        }
                    }
                }
                catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        };
        Thread t2=new Thread(){
            @Override
            public void run() {
                try{
                    for(int i=0;i<10;i++){
                        synchronized(lock1){
                            lock1.wait();;
                        }
                        System.out.print("B");
                        synchronized (lock2){
                            lock2.notify();
                        }
                    }
                }
                catch (InterruptedException e){
                    e.printStackTrace();
                }

            }
        };
        Thread t3=new Thread(){
            @Override
            public void run() {
                try{
                    for(int i=0;i<10;i++){
                        synchronized(lock2){
                            lock2.wait();;
                        }
                        System.out.println("C");
                        synchronized (lock3){
                            lock3.notify();
                        }
                    }
                }
                catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        };
        t1.start();;
        t2.start();
        t3.start();
    }
}
